package com.ballmaze.maze;

import java.util.HashMap;

public class MazeLoginManager {
    HashMap<String, Integer> recMap;
    int maxPlayerCount;
    int nowPlayerCount;

    public MazeLoginManager(int playerCount) {
        maxPlayerCount = playerCount;
        init();
    }

    private void init() {
        recMap = new HashMap<>();
        nowPlayerCount = 0;
    }

    public boolean insertPlayer(String username) {
        if (nowPlayerCount < maxPlayerCount && !recMap.containsKey(username)) {
            recMap.put(username, nowPlayerCount);
            nowPlayerCount++;
            return true;
        }
        return false;
    }

    public Integer getIdByName(String username) {
        return recMap.get(username);
    }

    public boolean containsPlayer(String username) {
        return recMap.containsKey(username);
    }

    public int size() {
        return recMap.size();
    }

    public void restart() {
        init();
    }
}
